package cn.big.bigd.configure;

import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.servlet.DispatcherType;

/**
 * 
 * @author wangfan
 *
 */
@Configuration
public class BigdConfigure {
    @Bean
    public FilterRegistrationBean sitemeshFilter() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new MySiteMeshFilter());
        filterRegistrationBean.setDispatcherTypes(DispatcherType.FORWARD, DispatcherType.ERROR);

        return filterRegistrationBean;
    }

    @Bean
    public WebMvcConfigurerAdapter webMvcConfigurerAdapter(final CommonInterceptor commonInterceptor){
        return new WebMvcConfigurerAdapter() {
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                super.addInterceptors(registry);
                registry.addInterceptor(commonInterceptor).addPathPatterns("/**");
            }
        };
    }
}
